﻿package mortal.game.view.copy.escort.renderer
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.geom.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import frEngine.render.layer.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.view.activeTime.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.tileList.*;
    import mortal.mvc.core.*;

    public class EscortTaskCellRenderer extends G3DCellRenderer
    {
        private var _bg:GImageBitmap;
        private var _name:GImageBitmap;
        private var _selectIcon:GImageBitmap;
        private var _selectBg:GImageBitmap;
        private var _selectBg2:GImageBitmap;
        private var _starPanel:StarPanel;
        private var _rewardTxt:GTextFiled;
        private var _moneyTxt:GTextFiled;
        private var _expTxt:GTextFiled;
        private var _energyTxt:GTextFiled;
        private var _tEscortColor:TEscortColor;

        public function EscortTaskCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap("", 2, 0, null, this.add2D);
            this._selectBg = UIFactory.gImageBitmap("", 1, 24, this);
            this._selectBg2 = UIFactory.gImageBitmap("", -3, 24, this);
            this._selectIcon = UIFactory.gImageBitmap("", 130, 80, this);
            this._name = UIFactory.gImageBitmap("", 39, 39, this);
            var _loc_1:* = GlobalStyle.textFormatHuang2;
            _loc_1.size = 14;
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35161), 14, 83, 80, 25, this, _loc_1));
            this._starPanel = UIFactory.getUICompoment(StarPanel, 67, 85, this);
            this._starPanel.setStarStyle(ImagesConst.GuildWarStarS, ImagesConst.GuildWarStarSGray, 20);
            _loc_1 = _loc_1.center();
            this._rewardTxt = UIFactory.gTextField(Language.getString(35162), 39, 341, 100, 25, this, _loc_1);
            _loc_1 = _loc_1.left();
            this._expTxt = UIFactory.gTextField("", 32, 365, 170, 25, this, _loc_1);
            this._energyTxt = UIFactory.gTextField("", 32, 387, 170, 25, this, _loc_1);
            this._moneyTxt = UIFactory.gTextField("", 32, 409, 170, 25, this, _loc_1);
            Dispatcher.addEventListener(EventName.ActiveStart, this.updateActive);
            Dispatcher.addEventListener(EventName.ActiveEnd, this.updateActive);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg.dispose(param1);
            this._bg = null;
            this._name.dispose(param1);
            this._name = null;
            this._starPanel.dispose(param1);
            this._starPanel = null;
            this._rewardTxt.dispose(param1);
            this._rewardTxt = null;
            this._expTxt.dispose(param1);
            this._expTxt = null;
            this._energyTxt.dispose(param1);
            this._energyTxt = null;
            this._moneyTxt.dispose(param1);
            this._moneyTxt = null;
            this._selectBg.dispose(param1);
            this._selectBg = null;
            this._selectIcon.dispose(param1);
            this._selectIcon = null;
            this._selectBg2.dispose(param1);
            this._selectBg2 = null;
            this._tEscortColor = null;
            Dispatcher.removeEventListener(EventName.ActiveStart, this.updateActive);
            Dispatcher.removeEventListener(EventName.ActiveEnd, this.updateActive);
            super.disposeImpl(param1);
            return;
        }// end function

        private function updateActive(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SClientActive;
            if (_loc_2.type == EActiveType._EActiveTypeEscort)
            {
                this.updateReWard();
            }
            return;
        }// end function

        private function updateReWard() : void
        {
            var _loc_2:int = 0;
            var _loc_1:* = EscortRewardConfig.instance.getItemByLevel(Cache.instance.role.entityInfo.level);
            if (ActiveTimeUtil.isInDoubleTimeByType(EActiveType._EActiveTypeEscort))
            {
                _loc_2 = 2;
            }
            else
            {
                _loc_2 = 1;
            }
            if (_loc_1)
            {
                this._moneyTxt.htmlText = Language.getStringByParam(35163, _loc_2 * _loc_1.coin * this._tEscortColor.rate * 0.01);
                this._energyTxt.htmlText = Language.getStringByParam(35164, _loc_2 * _loc_1.vital * this._tEscortColor.rate * 0.01);
                this._expTxt.htmlText = Language.getStringByParam(35165, _loc_2 * _loc_1.exp * this._tEscortColor.rate * 0.01);
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:SEscortInfo = null;
            super.data = param1;
            this._tEscortColor = param1 as TEscortColor;
            if (this._tEscortColor)
            {
                this._name.imgUrl = "EscortColor_" + (this._tEscortColor.color + 3);
                this._starPanel.setStarNum((this._tEscortColor.color + 1), (this._tEscortColor.color + 1));
                this._rewardTxt.htmlText = this.getStr();
                this.updateReWard();
                _loc_2 = Cache.instance.copy.escort.sEscortInfo;
                if (_loc_2 && this._tEscortColor.color == _loc_2.color)
                {
                    this._selectBg.imgUrl = "EscortSelect_" + (this._tEscortColor.color + 1);
                    this._selectBg2.imgUrl = "EscortSelectBg_" + (this._tEscortColor.color + 1);
                    this._selectIcon.imgUrl = ImagesConst.EscortSelectIcon;
                }
                else
                {
                    this._selectBg.imgUrl = null;
                    this._selectIcon.imgUrl = null;
                    this._selectBg2.imgUrl = null;
                }
                isResCompl = true;
                this.add3DModel();
            }
            return;
        }// end function

        private function getStr() : String
        {
            var _loc_1:String = null;
            switch(this._tEscortColor.color)
            {
                case 0:
                {
                    _loc_1 = Language.getString(35166);
                    break;
                }
                case 1:
                {
                    _loc_1 = Language.getString(35167);
                    break;
                }
                case 2:
                {
                    _loc_1 = Language.getString(35168);
                    break;
                }
                case 3:
                {
                    _loc_1 = Language.getString(35169);
                    break;
                }
                case 4:
                {
                    _loc_1 = Language.getString(35170);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_1;
        }// end function

        private function add2D() : void
        {
            if (this.isDisposed)
            {
                return;
            }
            var _loc_1:* = this.bgPos;
            itemBg = new Img2D(null, this._bg.bitmapData, new Rectangle(0, -35, this._bg.width, this._bg.height + 35), true);
            itemBg.x = _loc_1.x;
            itemBg.y = _loc_1.y;
            rect3d.addImg(itemBg, Layer3DManager.BackGroudEffectLayer);
            return;
        }// end function

        override protected function add3DModel() : void
        {
            var _loc_1:Point = null;
            var _loc_2:BossInfo = null;
            var _loc_3:String = null;
            var _loc_4:String = null;
            var _loc_5:String = null;
            if (this.canAdd3DModel)
            {
                super.add3DModel();
                _loc_1 = this.bgPos;
                _loc_2 = BossConfig.instance.getInfoByCode(this._tEscortColor.bossCode);
                _loc_3 = _loc_2.mesh + ".md5mesh";
                _loc_4 = _loc_2.texture;
                _loc_5 = _loc_2.bone + ".skeleton";
                bodyPlayer = FrObjectPool.getObject(ActionPlayer, this);
                bodyPlayer.changeAction(ActionName.Stand);
                bodyPlayer.selectEnabled = false;
                bodyPlayer.play();
                bodyPlayer.scaleValue = 1;
                bodyPlayer.setRotation(0, 0, 0);
                bodyPlayer.load(_loc_3, _loc_5, _loc_4, rect3d.renderList);
                rect3d.addObject3d(bodyPlayer, _loc_1.x + 100, _loc_1.y + 270);
                bodyPlayer.rotationY = 45;
                this._bg.imgUrl = "EscortColorBg_" + (this._tEscortColor.color + 3);
            }
            return;
        }// end function

    }
}
